package sort;

import edu.princeton.cs.algs4.In;

public class Selection extends Example {
  public static void sort(Comparable[] a) {
    int N = a.length;
    for (int i = 0; i < N; i++) {
      int min = i;
      // 找到比当前a[i]小的元素坐标
      for (int j = i + 1; j < N; j++) {
        if (less(a[j], a[min])) {
          min = j;
        }
      }
      // 交换两个坐标的值
      exch(a, i, min);
    }
  }

  public static void main(String[] args) {
    String[] a = In.readStrings();
    sort(a);
    assert isSorted(a);
  }
}
